package com.newasia.server.controller;

import com.newasia.server.common.exception.BaseBusinessException;
import com.newasia.server.common.result.ResponseData;
import com.newasia.server.common.result.ResponseUtil;
import com.newasia.server.controller.form.ChangePassForm;
import com.newasia.server.controller.form.UserForm;
import com.newasia.server.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LiChong
 * @description 针对用户进行的操作
 * @date 2020/4/2
 */

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    IUserService userService;

    /**
     *用户注册
     */
    @PostMapping("/register")
    public ResponseData register(@RequestBody UserForm form){
        ResponseData data = userService.register(form);
        return new ResponseUtil().setSuccessMsg(data);
    }

    /**
     *发送手机验证码
     */
    @RequestMapping(value = "sendPhoneCode")
    public ResponseData sendPhoneCode(@RequestBody UserForm form) {
        ResponseData data = userService.sendPhoneCode(form);
        return new ResponseUtil().setSuccessMsg(data);
    }

    /**
     * 忘记密码
     */
    @RequestMapping(value = "/resetPass")
    public ResponseData resetPass(@RequestBody UserForm form){
        ResponseData data = userService.resetPass(form);
        return new ResponseUtil().setSuccessMsg(data);
    }

    /*
     *更换密码
     */
    @RequestMapping(value = "/changePass")
    public ResponseData changePass(@RequestBody ChangePassForm form){
        ResponseData data = userService.changePass(form);
        return new ResponseUtil().setSuccessMsg(data);
    }

    /*
     *更换手机号码第一步
     */
    @RequestMapping(value = "/updatePhoneFirst")
    public ResponseData updatePhoneFirst(@RequestBody UserForm form) {
        ResponseData data = userService.updatePhoneFirst(form);
        return new ResponseUtil().setSuccessMsg(data);
    }

    /*
     *更换手机号码第二步
     */
    @RequestMapping(value = "/updatePhoneSecond")
    public ResponseData updatePhoneSecond(@RequestBody UserForm form) {
        ResponseData data = userService.updatePhoneSecond(form);
        return new ResponseUtil().setSuccessMsg(data);
    }

    /**
     *微信绑定
     */
    @RequestMapping(value = "/bundlingWeiXin")
    public ResponseData bundlingWeiXin(@RequestBody UserForm form){
        ResponseData data = userService.bundlingWeChat(null);
        return new ResponseUtil().setSuccessMsg(data);
    }

    /**
     *微信解绑
     */
    @RequestMapping(value = "/unbundlingWeiXin")
    public ResponseData unbundlingWeiXin(){
        ResponseData data = userService.unbundlingWeChat();
        return new ResponseUtil().setSuccessMsg(data);
    }
}
